// 输入框组件实例

import { assignInWith } from 'lodash'
import type {
  cascaderConfigType,
  dateRangeConfigType,
  inputConfigType,
  radioGroupConfigType
} from '../../../../../types/index'
import BaseEntity from '../../BaseEntity'
import { uid } from 'uid'
import type { configType, slotFormConfigType } from '../../BaseEntity'
import { entityType } from '../..'
export default class CascaderEntity extends BaseEntity {
  constructor(config: configType, slotFormConfig: slotFormConfigType) {
    let baseConfig: configType = {
      class: ['draggable-form-hover'],
      style: { width: '100%' },
      field: 'Cascader_' + uid(4),
      label: '级联选择器',
      hideLabel: false,
      required: false
    }
    let baseSlotFormConfig = {
      modelValue: '',
      options: [
        ],
        checkStrictly:true
    }
    let componentConfig: cascaderConfigType = {
      customOptionsSource: {
        type: 'customDataSource',
        formItemConfig: {
          label: '自定义数据源'
        },
        formItemElement: {
          modelValue: [],
          dataSourceConfig: {
            url: 'http://localhost:15999/Test/getCasaderData',
            headers: [{
              key:'content-type',
              value:'application/json',
            }],
            method: 'GET',
            params: [{key:'',value:''}],
            data:[{key:'',value:''}],
            //string 类型的函数通过eval执行
            beforeRequest: `function preHandler(requestConfig){
	                      //发起请求前做一些处理 需要返回配置项
                        requestConfig.headers["authorization"]=localStorage.getItem("token")
                        console.log("requestConfig",requestConfig)
                        return requestConfig
              }`,
            afterRequest: `function afterHandler(result){
	                      //请求成功后对返回数据做一些处理 需要返回数据源
                         console.log("result",result)
                         return result
              }   
            `
          }
        }
      }
    }

    super(
      entityType.cascader,
      assignInWith(baseConfig, config),
      assignInWith(baseSlotFormConfig, slotFormConfig),
      componentConfig
    )
    this.initSlotFormConfig()
  }
  initSlotFormConfig() {
    //初始化表单组件可配置项 因为表单组件可配置项是根据表单组件所拥有得属性来定义的 配置项得值需要对应初始化实例得对应属性得值

  }
}
